#include <ArduinoJson.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial){}
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["Name"]="WeiyiGeek";
  root["Age"]=22;
  size_t len = root.measureLength(); //单行输出时候的长度
  size_t lenSize = len+1;
  char json[lenSize];       // 加上了一个 '\0'
  root.printTo(Serial);
  Serial.print("\n单行输出长度：");
  Serial.print(len);
  Serial.print("\n----------\n");
  
  size_t lenPretty = root.measurePrettyLength();
  size_t lenPrettySize = lenPretty+1;
  char jsonpretty[lenPrettySize];  //建立数组
  root.prettyPrintTo(jsonpretty,lenPrettySize); //将数据存入数组中 
  Serial.println(jsonpretty); //打印出多行
  Serial.print("多行输出长度：");
  Serial.print(lenPretty);
}

void loop() {
  // put your main code here, to run repeatedly:

}
